package com.keycloak.admin.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 *
 */
@Configuration
@EnableSwagger2
public class Swagger2Config {
    private static final String SWAGGER2_TITLE="用户注册系统";//标题
    private static final String SWAGGER2_SERVICE_URL="https://www.baidu.com/";//网址
    private static final String SWAGGER2_AUTHOR="xu";//作者
    private static final String SWAGGER2_CONTACT_URL="1367660902@qq.com";//联系人url
    private static final String SWAGGER2_CONTACT_EMAIL="1367660902@qq.com";//联系人电子邮箱


    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.keycloak.admin.controller"))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title(SWAGGER2_TITLE)
                .termsOfServiceUrl(SWAGGER2_SERVICE_URL)
                .contact(new Contact(SWAGGER2_AUTHOR,SWAGGER2_CONTACT_URL,SWAGGER2_CONTACT_EMAIL))
                .version("1.0")
                .build();
    }
}
